﻿using System;
using UnityEngine;

// Token: 0x02000144 RID: 324
[AddComponentMenu("RVP/C#/Vehicle Controllers/Steering Control", 2)]
[DisallowMultipleComponent]
public class SteeringControl : MonoBehaviour
{
	// Token: 0x060005DC RID: 1500 RVA: 0x0002E8A6 File Offset: 0x0002CAA6
	private void Start()
	{
		this.tr = base.transform;
		this.vp = (VehicleParent)F.GetTopmostParentComponent<VehicleParent>(this.tr);
		this.steerRot = this.rotationOffset;
	}

	// Token: 0x060005DD RID: 1501 RVA: 0x0002E8D8 File Offset: 0x0002CAD8
	private void FixedUpdate()
	{
		float num = this.vp.localVelocity.z / this.steerCurveStretch;
		float num2 = (!this.limitSteer) ? 1f : this.steerCurve.Evaluate((!this.applyInReverse) ? num : Mathf.Abs(num));
		this.steerAmount = this.vp.steerInput * num2;
		foreach (Suspension suspension in this.steeredWheels)
		{
			suspension.steerAngle = Mathf.Lerp(suspension.steerAngle, this.steerAmount * suspension.steerFactor * (float)((!suspension.steerEnabled) ? 0 : 1) * (float)((!suspension.steerInverted) ? 1 : -1), this.steerRate * TimeMaster.inverseFixedTimeFactor * Time.timeScale);
		}
	}

	// Token: 0x060005DE RID: 1502 RVA: 0x0002E9C4 File Offset: 0x0002CBC4
	private void Update()
	{
		if (this.rotate)
		{
			this.steerRot = Mathf.Lerp(this.steerRot, this.steerAmount * this.maxDegreesRotation + this.rotationOffset, this.steerRate * Time.timeScale);
			this.tr.localEulerAngles = new Vector3(this.tr.localEulerAngles.x, this.tr.localEulerAngles.y, this.steerRot);
		}
	}

	// Token: 0x040008A4 RID: 2212
	private Transform tr;

	// Token: 0x040008A5 RID: 2213
	private VehicleParent vp;

	// Token: 0x040008A6 RID: 2214
	public float steerRate = 0.1f;

	// Token: 0x040008A7 RID: 2215
	private float steerAmount;

	// Token: 0x040008A8 RID: 2216
	[Tooltip("Curve for limiting steer range based on speed, x-axis = speed, y-axis = multiplier")]
	public AnimationCurve steerCurve = AnimationCurve.Linear(0f, 1f, 30f, 0.1f);

	// Token: 0x040008A9 RID: 2217
	public bool limitSteer = true;

	// Token: 0x040008AA RID: 2218
	[Tooltip("Horizontal stretch of the steer curve")]
	public float steerCurveStretch = 1f;

	// Token: 0x040008AB RID: 2219
	public bool applyInReverse = true;

	// Token: 0x040008AC RID: 2220
	public Suspension[] steeredWheels;

	// Token: 0x040008AD RID: 2221
	[Header("Visual")]
	public bool rotate;

	// Token: 0x040008AE RID: 2222
	public float maxDegreesRotation;

	// Token: 0x040008AF RID: 2223
	public float rotationOffset;

	// Token: 0x040008B0 RID: 2224
	private float steerRot;
}
